export function setupConcurrentRequestInterceptor(http, syncCount = 3) {
  const requests = [];
  let count = 0;
  function interceptor(config) {
    if (count >= syncCount) {
      return new Promise((resolve) => requests.push(() => resolve(config)));
    }
    count++;
    return config;
  }

  function nextRequest() {
    count--;
    const request = requests.shift();
    request && request();
  }

  http.interceptors.request.use(interceptor, function (error) {
    return Promise.reject(error);
  });

  http.interceptors.response.use(
    function (res) {
      nextRequest();
      return res;
    },
    function (error) {
      nextRequest();
      return Promise.reject(error);
    }
  );
}
